import request from '@/utils/request'

// 获取GPS地址
export const address = (data, auth) => {
  const header = {}
  if (auth?.companyId) {
    header['company-id'] = auth.companyId
  }

  if (auth?.token) {
    header['Authorization'] = `Bearer ${auth.token}`
  }
  return request({
    url: '/v1/gps/address',
    method: 'get',
    params: data,
    headers: {
      ...header
    }
  })
}

// 获取GPS最新位置
export const newLocation = (data, auth) => {
  const header = {}
  if (auth?.companyId) {
    header['company-id'] = auth.companyId
  }

  if (auth?.token) {
    header['Authorization'] = `Bearer ${auth.token}`
  }

  return request({
    url: '/v1/gps/locate',
    method: 'get',
    params: data,
    headers: {
      ...header
    }
  })
}

// 获取GPS轨迹
export const history = (data, auth) => {
  const header = {}
  if (auth?.companyId) {
    header['company-id'] = auth.companyId
  }

  if (auth?.token) {
    header['Authorization'] = `Bearer ${auth.token}`
  }

  return request({
    url: '/v1/gps/history',
    method: 'get',
    params: data,
    headers: {
      ...header
    }
  })
}

// 获取停留时间
export const stopTime = (data, auth) => {
  const header = {}
  if (auth?.companyId) {
    header['company-id'] = auth.companyId
  }

  if (auth?.token) {
    header['Authorization'] = `Bearer ${auth.token}`
  }
  return request({
    url: '/v1/gps/stop',
    method: 'get',
    params: data,
    headers: {
      ...header
    }
  })
}

// 设置GPS围栏
export const setGpsFence = (data) => {
  return request({
    url: `/v1/gps/rail`,
    method: 'POST',
    data
  })
}

// 编辑GPS围栏
export const editGpsFence = (data) => {
  return request({
    url: `/v1/gps/rail`,
    method: 'PUT',
    data
  })
}

// 删除GPS围栏
export const removeGpsFence = (id, params) => {
  return request({
    url: `/v1/gps/rail/${id}`,
    method: 'DELETE',
    params
  })
}

// 获取GPS围栏列表
export const getFenceList = (params) => {
  return request({
    url: `/v1/gps/rail`,
    method: 'GET',
    params
  })
}

// 编辑GPS围栏名称
export const editFenceName = (data) => {
  return request({
    url: `/v1/gps/rail/${data.id}`,
    method: 'PUT',
    data
  })
}

// 获取GPS围栏警告类型
export const getWarningType = () => {
  return request({
    url: `/v1/gps/type`,
    method: 'GET'
  })
}

// 获取GPS围栏警告通知用户
export const getWarningNoticeUsers = () => {
  return request({
    url: `/v1/gps/mes`,
    method: 'GET'
  })
}

// 设置GPS围栏警告通知用户
export const setWarningNoticeUsers = (data) => {
  return request({
    url: `/v1/gps/mes`,
    method: 'POST',
    data
  })
}

// 获取GPS围栏警告列表
export const getWarningNoticeList = (params) => {
  return request({
    url: `/v1/gps/notice`,
    method: 'GET',
    params
  })
}
